'use strict';
import Base from './base.js';

export default class extends Base {

	// 获取订单
	async getShopOrderAction () {
		let filter = this.get()
		let where = {}
		if (filter.orderType) {
			where['o.ordertype'] = filter.orderType
		}
		// 如果有id取id没有查全部
		if (filter.shopId) {
			where['o.departmentid'] = filter.shopId
		} else {
			let shopList = await this.model('or_department').where({pid: this.userinfo.departmentid}).getField('id')
			if (shopList.length) {
				where['o.departmentid'] = ['in', shopList]
			}
		}

		if (filter.search) {
			where['o.order_sn'] = ['like', '%' + filter.search + '%']
		}

		let orderList = await this.model('or_shop_order')
		.alias('o')
		.join('think_or_department d on o.departmentid = d.id')
		.field('o.*, d.name as dname')
		.where(where)
		.page(filter.pages, filter.limits)
		.countSelect()
		return this.json(orderList)
	}

	// 更改订单时间
	async changeOrderTimesAction () {
		let data = this.post()
		// 有哪些表需要更改
		// 
	}
}